// 表格参数校验

const regs = {
  email: /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,
  number: /^[0-9]+$/,
  password: /^(?=.*[a-zA-Z])(?=.*\d)[a-zA-Z\d]{8,18}$/,
  shareCode: /^[a-zA-Z0-9]+$/,
};

const verify = (rule, value, reg, callback) => {
  if (value && value != "") {
    if (reg.test(value)) {
      // console.log("校验通过");
      callback();
    } else {
      callback(new Error(rule.message));
    }
  } else {
    // console.log("参数异常");
    callback();
  }
};

export default {
  email: (rule, value, callback) => {
    return verify(rule, value, regs.email, callback);
  },
  number: (rule, value, callback) => {
    return verify(rule, value, regs.number, callback);
  },
  password: (rule, value, callback) => {
    return verify(rule, value, regs.password, callback);
  },
  shareCode: (rule, value, callback) => {
    return verify(rule, value, regs.shareCode, callback);
  },
};
